package com.sq.partner.manager.service.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sq.partner.manager.common.Result;
import com.sq.partner.manager.dao.TradCheckcontactsDao;
import com.sq.partner.manager.dao.TradPlanSaleDao;
import com.sq.partner.manager.mybatis.model.TradCheckcontacts;
import com.sq.partner.manager.mybatis.model.TradPlanSale;
import com.sq.partner.manager.mybatis.model.TradSaleAgent;
import com.sq.partner.manager.service.IGatewayClearCacheManager;
import com.sq.partner.manager.service.TradCheckcontactsService;
import com.sq.partner.manager.service.TradPlanSaleService;
import com.sq.partner.manager.util.Page;

/**
 * 对账联系人管理
 * @author menyanlei
 *
 */
@Service
public class TradCheckcontactsServiceImpl implements TradCheckcontactsService{
	@Resource
	TradCheckcontactsDao tradCheckcontactsDao;
	/***
	 * 分页查询
	 */
	@Override
	public Page queryCheckcontactsPageByCriteria(Page page) throws Exception {
		Map<String,Object> map=page.getMap();
		Integer count=(Integer) tradCheckcontactsDao.query("selectTradCheckCount", map);
		page.setTotal(count);
		List<TradCheckcontacts> list= (List<TradCheckcontacts>) tradCheckcontactsDao.queryList("selectTradCheckcontacts", map);
		page.setData(list);
		return page;
	}
	@Override
	public Result addCheckcontacts(TradCheckcontacts tradCheckcontacts)
			throws Exception {
		/**查询是否已存在， 机构信息，合作伙伴代码**/
		TradCheckcontacts trad=(TradCheckcontacts) tradCheckcontactsDao.query("selectchecksByid", tradCheckcontacts);
		if(trad!=null){
			return Result.error("此机构下已存在合作伙伴联系人");
		}
		tradCheckcontactsDao.insertTradCheck(tradCheckcontacts);
		return Result.success("操作成功");
	}
	@Override
	public Result editCheckcontacts(TradCheckcontacts tradCheckcontacts)
			throws Exception {
		tradCheckcontactsDao.updateTradCheck(tradCheckcontacts);
		return  Result.success("操作成功");
	}
	@Override
	public Result deleteCheckcontacts(TradCheckcontacts tradCheckcontacts)
			throws Exception {
		
		tradCheckcontactsDao.deleteTradCheck(tradCheckcontacts);
		
		return  Result.success("操作成功");
		
	}
	
}
